package com.bjc.platform.web.controller;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bjc.platform.model.AdmCode;
import com.bjc.platform.service.AdmCodeService;
import com.bjc.platform.util.StaticMethod;
import com.bjc.platform.web.controller.BaseController;

/**
 * 
 * 控制器映射和处理与数据库adm_code表相关的HTTP请求
 * 
 */
@Controller
public class AdmCodeController extends BaseController {

	@Autowired
	@Qualifier("admCodeService")
	/** AdmCode业务逻辑处理器 */
	private AdmCodeService admCodeService = null;

	/**
	 * 根据adm_code.code查询对应的子类别代码数据
	 * 
	 * @param request
	 *            HttpServletRequest
	 * @return 以JSON格式返回子类别代码数据
	 */
	@RequestMapping(value = "/queryAdmCode", method = RequestMethod.GET)
	@ResponseBody
	public Object queryAdmCode(HttpServletRequest request) {
		String codeType = request.getParameter("codeType");
		// 流水查询不用列出盘存选项
		if ("SOT_FLOW".equals(codeType)) {
			codeType = "SOT";
			List<AdmCode> admCode = admCodeService.queryChildrenByCode(codeType);
			Iterator<AdmCode> iter = admCode.iterator();
			while (iter.hasNext()) {
				AdmCode ac = iter.next();
				if (ac.getCode().equals("SOT_AW")) {
					iter.remove();
					break;
				}
			}
			return StaticMethod.TOJSONResult(true, admCode).getJSONResult();
		}
		List<AdmCode> admCode = admCodeService.queryChildrenByCode(codeType);
		return StaticMethod.TOJSONResult(true, admCode).getJSONResult();
	}

}
